package cn.wolfcode.wolf2w.controlle;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.query.QueryObject;
import cn.wolfcode.wolf2w.query.RegionQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/region")
public class RegionController {

    @Autowired
    private IRegionService regionService;
    @Autowired
    private IDestinationService destinationServicep;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") RegionQuery qo) {
        //分页查询
        Page<Region> page = regionService.query(qo);
        model.addAttribute("page", page);
        return "region/list";
    }

    @RequestMapping("/listDests")
    @ResponseBody
    //查询所有的目的地
    public Object listDests() {
        return destinationServicep.list();
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    //保存修改
    public Object saveOrUpdate(Region region) {
        regionService.saveOrUpdate(region);
        return JsonResult.success();
    }

    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(String rid) {
        //返回值是什么类型，就用哪个类型的服务
        List<Destination> list =destinationServicep.getDestByRegionId(rid);
        return list;
    }
    @RequestMapping("/changeHotValue")
    @ResponseBody
    //区域热门修改
    public Object changeHotValue(int hot,String id) {
       regionService.changeHotValue(hot,id);
        return JsonResult.success();
    }
    //删除
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
       regionService.delete(id);
        return JsonResult.success();
    }



}
